<template>
    <a-form-item :label="label">
        <a-select allowClear v-model:value="Parmas[itemkey]" :placeholder="InputPlaceholder">
            <a-select-option :value="item.value" v-for="item in SelectOptions" :key="item.value">
                {{ item.label }}
            </a-select-option>
        </a-select>
    </a-form-item>
</template>
<script setup>
import { computed, inject, onMounted } from "vue"
const props = defineProps(['label', 'itemkey', 'placeholder', 'options'])
const Parmas = inject('Parmas');

const GetDict = inject('GetDict');

const InputPlaceholder = computed(() => {
    return props.placeholder ? this.placeholder : ('请输入' + props.label);
});

const SelectOptions = ref([]);

const changeOptions = async function (options) {
    if (typeof props.options == 'function') {
        this.SelectOptions = await options();
    } else if (typeof props.options == 'string') {
        this.SelectOptions = GetDict(props.options);
    } else {
        this.SelectOptions = options || this.options
    }
}


onMounted(() => {
    changeOptions();
})


defineExpose({
    changeOptions
})

</script>
<style lang="less" scoped></style>